package com.example.administrator.zhongyichou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.zhongyichou.help.DateUtils;
import com.example.administrator.zhongyichou.help.ImageLoader;
import com.example.administrator.zhongyichou.help.StringImageToList;
import com.example.administrator.zhongyichou.net.protocol.HomeProtocol;
import com.example.administrator.zhongyichou.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lichenyu on 2017/12/4.
 * 描述：
 */

public class HomeFragmentAdapter2 extends ListBaseAdapter {

    public HomeFragmentAdapter2(Context mContext, List list) {
        super(mContext, list);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.home_fragment_item4, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        HomeProtocol.DataBean.DreamListBean bean = (HomeProtocol.DataBean.DreamListBean) getData(position);
        holder.txtTitle.setText(bean.getInfo_title());
        ImageLoader.centerCropUrl(getContext(), StringImageToList.toImage(bean.getInfo_img()), holder.imgContent);
        holder.txtName.setText(bean.getUser_acc());
        holder.txtTime.setText(DateUtils.stampToDate(bean.getAudit_time()));
        holder.txtAimsMoney.setText(bean.getAims_money() + "元");
        holder.txtGotMoney.setText(bean.getGot_money() + "元");
        holder.txtRaiseNum.setText(bean.getRaise_num());
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.txt_title)
        TextView txtTitle;
        @BindView(R.id.img_content)
        ImageView imgContent;
        @BindView(R.id.txt_name)
        TextView txtName;
        @BindView(R.id.txt_time)
        TextView txtTime;
        @BindView(R.id.txt_aims_money)
        TextView txtAimsMoney;
        @BindView(R.id.txt_got_money)
        TextView txtGotMoney;
        @BindView(R.id.txt_raise_num)
        TextView txtRaiseNum;
        @BindView(R.id.view_big)
        LinearLayout viewBig;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
